package cjlu.ea.h.controller;

import cjlu.ea.h.api.ExcelApi;
import cjlu.ea.h.common.R;
import cjlu.ea.h.entity.Bjxx;
import cjlu.ea.h.entity.ByszgshbLsb;
import cjlu.ea.h.entity.DBsyxwsqb;
import cjlu.ea.h.entity.DBysfxshb;
import cjlu.ea.h.service.F101ByszgshbLsbService;
import cjlu.ea.h.service.F102DBsyxwsqbService;
import cjlu.ea.h.service.F103DBysfxshbService;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;

import java.io.InputStream;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/excel/")
public class ExcelController {



    @Autowired
    ExcelApi excelApi;

    @PostMapping("exportbys")
    public void export(HttpServletResponse response,
                       @RequestBody ByszgshbLsb byszgshbLsb) {

        excelApi.F101Export(response,byszgshbLsb);

    }

    @PostMapping("importbys")
    public R importExcel(MultipartFile file){

        Boolean res = excelApi.F101Import(file);

        if (res){
            return R.ok();
        }
        return R.error();
    }
    @PostMapping("exporttsbys")
    public void exporttsbys(HttpServletResponse response,
                       @RequestBody DBsyxwsqb dBsyxwsqb) {

        excelApi.F102Export(response,dBsyxwsqb);

    }

    @PostMapping("importtsbys")
    public R importtsbysExcel(MultipartFile file){

        Boolean res = excelApi.F102Import(file);

        if (res){
            return R.ok();
        }
        return R.error();
    }
    @PostMapping("exportsxbys")
    public void exportsxbys(HttpServletResponse response,
                            @RequestBody DBysfxshb dBysfxshb) {

        excelApi.F103Export(response,dBysfxshb);

    }

    @PostMapping("importsxbys")
    public R importsxbysExcel(MultipartFile file){

        Boolean res = excelApi.F103Import(file);

        if (res){
            return R.ok();
        }
        return R.error();
    }
    @PostMapping("exportbj")
    public void exportbj(HttpServletResponse response,
                         @RequestBody Bjxx bjxx) {

        excelApi.F201Export(response,bjxx);

    }

    @PostMapping("importbj")
    public R importbjExcel(MultipartFile file){

        Boolean res = excelApi.F201Import(file);

        if (res){
            return R.ok();
        }
        return R.error();
    }

    @PostMapping("exportF1011")
    public R exportF1011(HttpServletResponse response,
                         @RequestBody Bjxx bjxx){
        excelApi.F1011Export(response,bjxx);
        return R.ok();
    }
    @PostMapping("exportF1012")
    public R exportF1012(HttpServletResponse response,
                         @RequestBody Bjxx bjxx){
        excelApi.F1012Export(response,bjxx);
        return R.ok();
    }
    @PostMapping("exportF1013List")
    public R exportF1013List(HttpServletResponse response,
                         @RequestBody Bjxx bjxx){
        excelApi.F1013ListExport(response,bjxx);
        return R.ok();
    }
    @PostMapping("exportF1013")
    public R exportF1013(HttpServletResponse response,
                         @RequestBody Bjxx bjxx){
        excelApi.F1013Export(response,bjxx);
        return R.ok();
    }

    @PostMapping("exportF1014List")
    public R exportF1014List(HttpServletResponse response,
                             @RequestBody Bjxx bjxx){
        excelApi.F1014ListExport(response,bjxx);
        return R.ok();
    }
    @PostMapping("exportF1014")
    public R exportF1014(HttpServletResponse response,
                         @RequestBody Bjxx bjxx){
        excelApi.F1014Export(response,bjxx);
        return R.ok();
    }
    @PostMapping("exportF1015List")
    public R exportF1015List(HttpServletResponse response,
                             @RequestBody Bjxx bjxx){
        excelApi.F1015ListExport(response,bjxx);
        return R.ok();
    }


}